// FloatingOrigin.cpp
//
#include "FloatingOrigin.h"

#include "OpenGL.h"

#include <iostream>

using namespace OpenGL;

//Math::vec3 FloatingOrigin::origin  = Math::vec3(0,0,0);
//bool FloatingOrigin::enabled       = false;

// ------------------------------------------------------------------------------------------------
FloatingOrigin::FloatingOrigin()
: origin(0,0,0),
  enabled(false)
{}

// ------------------------------------------------------------------------------------------------
FloatingOrigin::~FloatingOrigin()
{}

// ------------------------------------------------------------------------------------------------
void FloatingOrigin::enable( bool on )
{
	enabled = on;

	//if( enabled )
	//{
	//	const std::string vtx = STRINGIFY
	//	(
	//		uniform vec4 u_origin;

	//		void main()
	//		{
	//			gl_Position       = gl_ModelViewProjectionMatrix * gl_Vertex;
	//			gl_FrontColor     = gl_Color;
	//		}		
	//	);

	//	s.set(vtx);
	//	if( !s.isLinked() )
	//		std::cout << s.getInfoLog() << std::endl ;
	//}
}

// ------------------------------------------------------------------------------------------------
void FloatingOrigin::set(const Math::dvec3 &c)//{ origin = c; }
{
	if( enabled )	{ origin = c;	}
	else			{ origin = Math::vec3(0,0,0);
					  glTranslated(-c[0], -c[1], -c[2]);	}
}

// ------------------------------------------------------------------------------------------------
//void FloatingOrigin::set(const Math::dvec2 &c) { origin = Math::dvec3(c[0],c[1],0); }
//{
//	if( enabled )	{ origin = Math::vec3(c[0],c[1],0);	}
//	else			{ origin = Math::vec3(0,0,0);
//					  /*glTranslated(-c[0], -c[1], -c[2]);*/	}
//}


// ------------------------------------------------------------------------------------------------
//void FloatingOrigin::bind()
//{
//	if( enabled )
//	{
//		//s.bind();
//		//s.uniform("u_origin",origin.x,origin.y,origin.z,0.0);
//	}
//	else
//	{
//		glTranslated( -origin[0], -origin[1], -origin[2] );
//	}
//}
//
//// ------------------------------------------------------------------------------------------------
//void FloatingOrigin::unbind()
//{
//	s.bindFixedPipeline();
//}


// ------------------------------------------------------------------------------------------------
Math::dvec3 FloatingOrigin::get() const { return origin; }/*{ return enabled ? origin : Math::dvec3(0); }*/
//Math::dvec2 FloatingOrigin::get2D() const { return enabled ? Math::dvec2(origin[0],origin[1]) : Math::dvec2(0); }